import 'package:flutter/material.dart';
import 'package:flutter_blue_plus/flutter_blue_plus.dart';
import 'package:flutter_screenutil/flutter_screenutil.dart';
import 'package:get/get.dart';
import 'package:lifecycle/lifecycle.dart';
import '../../../style/app_colors.dart';
import '../controllers/device_connection_controller.dart';

class DeviceConnectionView extends GetView<DeviceConnectionController> {
  const DeviceConnectionView({super.key});
  @override
  Widget build(BuildContext context) {
    return LifecycleWrapper(
      onLifecycleEvent: (event) {
        print('lifecycle event:: $event');
        if (LifecycleEvent.active == event) {
          controller.setToStopCan(false);
          controller.startAutoScan();
        } else if (LifecycleEvent.inactive == event) {
          controller.stopScan();


        }
      },
      child: Scaffold(
        appBar: AppBar(
          leading: IconButton(
            icon: Image.asset('assets/images/ic_back2.png',width: 48.w,height: 48.h),
            onPressed: () {
              FlutterBluePlus.stopScan();
              Get.back();
            },
            tooltip: MaterialLocalizations.of(context).backButtonTooltip, // 可选：设置工具提示
          ),
        ),
        body: Container(
          child: ListView(
              children: [
                SizedBox(height: 4.h),
                Row(
                  mainAxisAlignment: MainAxisAlignment.center,
                  children: [
                    Text('请将手机靠近悟空机器人',style: TextStyle(fontSize: 48.sp,color: AppColors.Page_Title_Color),),
                  ],
                ),
                SizedBox(height: 200.h),
                Image.asset('assets/images/close_to_robot.webp',height: 570.h),
                SizedBox(height: 396.h),
                /*controller.showTips.value ? Row(
                mainAxisAlignment: MainAxisAlignment.center,
                children: [
                  Text('未发现设备,请手动连接重新尝试.',style: TextStyle(color: AppColors.secondaryText,fontSize: 14.sp)),
                ],
              ) : SizedBox(),*/
                GestureDetector(
                  onTap: () {
                    controller.goToManualConnect();
                  },
                  child: Container(
                    margin: EdgeInsets.only(left: 79.w,right: 78.w),
                    width: 594.w,
                    height: 88.h,
                    child: Column(
                      mainAxisAlignment: MainAxisAlignment.center,
                      children: [
                        Text('手动连接机器人',style: TextStyle(color: Colors.blue,fontSize: 28.sp))
                      ],
                    ),
                  ),
                )

              ]

          ),
        ),
      ),
    );
  }
}
